package com.ruoyi.web.controller.ucenter.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.model.auth.AuthContextHolder;
import com.ruoyi.model.user.UserCheck;
import com.ruoyi.ucenter.service.IUserCheckService;
import com.ruoyi.ucenter.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 申请组织Controller
 *
 * @author ruoyi
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/admin/u-audit")
public class UserCheckAdminController extends BaseController {
    @Autowired
    private IUserCheckService userCheckService;

    /**
     * 查询申请组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserCheck userCheck)
    {
        startPage();
        List<UserCheck> list = userCheckService.selectUserCheckList(userCheck);
        return getDataTable(list);
    }

    /**
     * 导出申请组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "申请组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserCheck userCheck)
    {
        List<UserCheck> list = userCheckService.selectUserCheckList(userCheck);
        ExcelUtil<UserCheck> util = new ExcelUtil<UserCheck>(UserCheck.class);
        util.exportExcel(response, list, "申请组织数据");
    }

    /**
     * 获取申请组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(userCheckService.selectUserCheckById(id));
    }

    /**
     * 修改申请组织
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "申请组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCheck userCheck)
    {
        return toAjax(userCheckService.auditUserCheck(userCheck));
    }
}
